package com.popcorn.member.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.popcorn.action.Action;
import com.popcorn.action.ActionForward;
import com.popcorn.member.dao.MemberDAO;
import com.popcorn.member.model.MemberVo;

public class MemberInsertAction implements Action {

	@Override
	public ActionForward execute(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter("member_id");
		String name = request.getParameter("member_name");
		String nickname = request.getParameter("member_nickname");
		String password = request.getParameter("member_password");
		String hp1 = request.getParameter("hp1");
		String hp2 = request.getParameter("hp2");
		String hp3 = request.getParameter("hp3");
		String hp = hp1+"-"+hp2+"-"+hp3;
		
		MemberVo vo = new MemberVo();
		vo.setHp(hp);
		vo.setId(id);
		vo.setName(name);
		vo.setNickname(nickname);
		vo.setPwd(password);
		
		MemberDAO dao = new MemberDAO();
		boolean result = dao.insertVo(vo);
		
		ActionForward forward = new ActionForward();
		
		if(result==true){
			forward.setRedirect(false);
			forward.setPath("../main/main.jsp");
		}else{
			forward.setRedirect(false);
			forward.setPath("member.jsp");
		}
		
		return forward;
	}
}
